package com.exam.danangtranel.adapter;

import java.util.List;

import com.exam.danangtranel.filed.Hotel;

import com.example.danangtravel.R;
import com.example.danangtravel.Restaurant.Actitivy_Details;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class TbFoodAdapter extends BaseAdapter {
	public Context context;
	public List<Hotel> list;
	public OnClickListener listenner;

	// public ContactDataSource data ;
	public TbFoodAdapter(Context context, List<Hotel> list) {
		this.context = context;
		this.list = list;
	}

	public void setButtonListenner(OnClickListener listenner) {
		this.listenner = listenner;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return (Hotel) list.get(arg0);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		// data = new ContactDataSource(context.getApplicationContext());
		ViewHolder viewHolder;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.row_food, null);
			viewHolder = new ViewHolder();
			viewHolder.name = (TextView) convertView
					.findViewById(R.id.row_food_list_name);
			viewHolder.add = (TextView) convertView
					.findViewById(R.id.row_food_list_add);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.name.setText(list.get(position).getName());

		viewHolder.add.setText(list.get(position).getAdrress());

		convertView.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent myIntent=new Intent(context.getApplicationContext(), Actitivy_Details.class);
//				String id=String.valueOf(position+1);
				myIntent.putExtra("idoftableFoodies", list.get(position).getID());
//				myIntent.putExtra("lat", list.get(position).getLatitude());
//				myIntent.putExtra("long", list.get(position).getLongitude());
//				myIntent.putExtra("type", list.get(position).getType());
				context.startActivity(myIntent);
//				Toast.makeText(context, "id"+list.get(position).getID(), 1000).show();
//				Toast.makeText(context, "type"+list.get(position).getType(), 1000).show();
//				Toast.makeText(context, "item"+position, 1000).show();
//				Toast.makeText(context, "item"+position, 1000).show();
			}
		});
		return convertView;

	}

	static class ViewHolder {
		TextView name, add;
	}
}
